<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var obj = {
      name: 'zs'
    }
    function fn1(a, b) {
      console.log(this);
      console.log(a + b);
      return a + b
    }
    // 让函数中的this指向obj,后面为参数
    // call方法的两个作用：1. 调用函数（可以传参数调用）；
    //                    2. 改变函数的this指向
    var one = fn1.call(obj, 2, 3)
    console.log(one);
    // call主要用于继承
    // 父类
    function Father(name, age, sex) {
      this.name = name
      this.age = age
      this.sex = sex
    }

    // 子类
    function Son(name, age, sex) {
      Father.call(this, name, age, sex)
    }
    var son = new Son('张三', 28, '男')
    console.log(son);
  </script>
</body>

</html>